<?php

declare(strict_types=1);

namespace app\admin\model;

use app\common\AliYunOss\Image;
use think\Model;

/**
 * @mixin \think\Model
 */
class Filingcabinet extends BaseModel
{
    //
    // 设置表名
    protected $name = 'filingcabinet';

    protected $attributes = [
        'file_type' => [
            10 => '合同(原件)[未签署]',
            20 => '合同(正式)[已签署]',
            80 => '其他',
        ],
    ];
    public function getFileTypeValueAttr($value, $data)
    {
        if (!isset($data['file_type'])) {
            return '未知';
        }
        return $this->attributes['file_type'][$data['file_type']] ?? '未知';
    }
    // 让查询结果自动附加 file_type_value
    protected $append = ['file_type_value'];
    // 关联普通订单
    public function order()
    {
        return $this->hasOne(Order::class, 'id', 'order_id')
            ->bind(['order_no']);
    }

    // 关联经销商订单
    public function wholesalOrder()
    {
        return $this->hasOne(WholesalOrder::class, 'id', 'order_id')
            ->bind(['order_no']);
    }

    // 关联客户信息
    public function customer()
    {
        return $this->hasOne(Customer::class, 'id', 'customer_id')
            ->bind(['customer_name' => 'cusname']);
    }

    // 关联creator
    public function creator()
    {
        return $this->hasOne(Operator::class, 'id', 'creator')
            ->bind(['creator_name' => 'cname']);
    }


    // images
    public function images()
    {
        return $this->hasOne(Images::class, 'id', 'file_id')
            ->bind(['file_url' => 'url']);
    }
}
